/*
理解形参和实例参数化，fun函数的两个形参类型是固定的
function fun(name: string, age: number): void {
    console.log(name,age)
}
*/

function foo<Type>(arg: Type): Type {
    return arg
}

/* 泛型的完整写法 */
const res1: number = foo<number>(100)
console.log(res1.toFixed(3))

const res2: string = foo<string>("陶品奇")
console.log(res2.length)

interface InterfacePerson {
    name: string,
    age: number
}

const res3: InterfacePerson = foo<InterfacePerson>({name: "马云", age: 22})
console.log(res3.name, res3.age)


/* 泛型的省略写法 */
const res4: "123456" = foo("123456")
let res5: string = foo("哈哈哈")
console.log(res4,res5)